import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'

import Tenant from '../views/admin/Tenant'
import UpmsApp from '../views/admin/UpmsApp'
import Admin from '../views/admin/Admin'
import User from '../views/admin/User'
import Api from '../views/admin/Api'
import Config from '../views/admin/Config'
import ApiVisit from '../views/admin/ApiVisit/'
import OpRole from '../views/admin/OpRole'

// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
  mode: 'history',
  // 页面跳转后，页面是否滚动
  scrollBehavior: () => ({y: 0}),
  routes: [
    {
      path: '/admin',
      component: Layout,
      children: [
        {path: '/admin/', name: 'tenant', component: Tenant},
        {path: '/admin/app', name: 'app', component: UpmsApp},
        {path: '/admin/admin', name: 'admin', component: Admin},
        {path: '/admin/user', name: 'user', component: User},
        {path: '/admin/api', name: 'api', component: Api},
        {path: '/admin/config', name: 'config', component: Config},
        {path: '/admin/apiVisit', name: 'apiVisit', component: ApiVisit},
        {path: '/admin/opRole', name: 'opRole', component: OpRole}
      ]
    },
    {
      path: '/admin/login',
      name: 'login',
      component: Login
    }
  ]
})
